from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QVBoxLayout, QTextEdit
from PyQt5.QtCore import *
import sys


def init_widget(w: QWidget):
    
    #创建垂直布局Vertical
    layout = QVBoxLayout()
    
    edit = QLineEdit()
    edit.setPlaceholderText("请输入用户名")
    #设置默认内容
    edit.setText("KZZ-260")
    # 设置输入框最大的字符数
    edit.setMaxLength(10)
    layout.addWidget(edit)
    
    # 获取文本框内容
    print('edit:', edit.text())
     
    edit_pwd = QLineEdit()
    edit_pwd.setPlaceholderText("请输入密码")
    # 设置内容显示模式
    edit_pwd.setEchoMode(QLineEdit.PasswordEchoOnEdit)
    layout.addWidget(edit_pwd)
    
    # 多行文本输入 QTextEdit
    text_edit = QTextEdit()
    text_edit.setPlaceholderText("请输入个人介绍")
    # 设置文本内容
    text_edit.setPlainText("我叫赵留刚，来自贵州")
    # 获取已经输入的内容
    print(text_edit.toPlainText())
    layout.addWidget(text_edit)
    
    w.setLayout(layout)

if __name__ == '__main__':
    # 1. 创建应用程序
    app = QApplication(sys.argv)

    # 2. 创建窗口
    w = QWidget()
    # 创建标题
    w.setWindowTitle("KZZ-260上位机")
    w.resize(400, 300)

    init_widget(w)

    # 3. 显示窗口
    w.show()

    # 4. 等待APP停止
    sys.exit(app.exec_())